<?php

/**
 * Class CommodityTag_Model
 */
class CommodityTag_Model extends CI_Model
{
    /**
     *
     */
    public function __construct()
    {
        parent::__construct();
    }

    public static function getAllResultArray(){
        /** @var CI $CI */
        $CI =& get_instance();

        $CI->db->select('commodity_tag.*');
        $CI->db->from('commodity_tag');

        $query  = $CI->db->get();
        $result = $query->result();

        return $result;
    }

    public static function getAllResultArrayByKeyword($keyword){
        if(!$keyword)return null;
        /** @var CI $CI */
        $CI =& get_instance();

        $CI->db->select('commodity_tag.*');
        $CI->db->from('commodity_tag');
        $CI->db->like('name', $keyword);
        $CI->db->limit(10);

        $query  = $CI->db->get();
        $result = $query->result();

        return $result;
    }



    /**
     * @param string $tagName
     * @return bool
     */
    public static function addCommodityTag($tagName)
    {
        /** @var CI $CI */
        $CI =& get_instance();

        $result = $CI->db->insert('commodity_tag', array( 'name' => $tagName));

        if ($result)
            return true;
        else
            return false;
    }


    /**
     * @param int $id
     * @return bool
     */
    public static function deleteCommodityTag($id)
    {
        /** @var CI $CI */
        $CI =& get_instance();

        $CI->db->where('commodity_tag.id', $id);

        $result = $CI->db->delete('commodity_tag');
        if ($result)
            return true;
        else
            return false;
    }


}
